/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.commands
{
	import com.adobe.cairngorm.control.CairngormEvent;	
	import com.adobe.cairngorm.commands.ICommand;
	import virtPresenter.event.PlayStopVideoPlayerEvent;
	import virtPresenter.model.virtPresenterLocator;
	import virtPresenter.event.CairngormErrorEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	/**
	 * Command lets the VideoPlayer play, pause or stop.
	 * */
	public class PlayStopCommand implements ICommand
	{	
		/**
		 * Handles if the video in the VideoPlayer shall be paused, played or stopped.
		 * */
		public function execute(event:CairngormEvent):void
		{
			var locator : virtPresenterLocator = virtPresenterLocator.getInstance();
			var e:PlayStopVideoPlayerEvent =PlayStopVideoPlayerEvent(event);
			var type:String =e._type;
			
			if(locator.netStream!=null){
				switch(type)
				{
					case PlayStopVideoPlayerEvent.PLAY:
						locator.netStream.resume();
						locator.defaultView.videoPlayer.currentState='activeState';
						locator.defaultView.setCurrentState('Pause_State');
					break;
					case PlayStopVideoPlayerEvent.PAUSE:
						locator.netStream.pause();
						locator.defaultView.videoPlayer.currentState='initState';
						locator.defaultView.setCurrentState('Play_State');
					break;
					case PlayStopVideoPlayerEvent.STOP:
					   locator.netStream.pause();
					   locator.netStream.seek(0);
					   locator.defaultView.videoPlayer.playing=false;
					   locator.defaultView.videoPlayer.currentState='initState';
					   locator.defaultView.setCurrentState('Play_State');
				}
			}
			
			if(locator.netStream==null){	
				var err:VerifyError=new VerifyError("PlayStopCommand. Currently the Videoserver is down for maintenance.");
				CairngormEventDispatcher.getInstance().dispatchEvent(new CairngormErrorEvent(err,"Please contact mketterl@uos.de"));
			}
		}	
	
	}
}